package com.host.tab;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.database.Cursor;
import android.provider.CallLog;

public class Filter {

	//private filter_filter_filter_filter_cursor filter_filter_filter_filter_cursor;
	private Context context;
	
	private static final String IncomingCall = "1";
	private static final String OutgoingCall = "2";
	private static final String MissedCall = "3";

	private static String Incoming_text = "来电";
	private static String Outgoing_text = "去电";
	private static String Missed_text = "未接来电";
	
	public static String temp_name = null;
	public static String temp_number = null;
	public static String temp_type = null;
	public static String temp_date = null;
	public static String temp_duration = null;
	public static String temp_times = null;
	
	public Filter(Context context){
		this.context = context;
	}
	
	public static List<Map<String, Object>> Display_Incoming(Cursor filter_cursor){
		List<Map<String, Object>> list_incoming = new ArrayList<Map<String, Object>>();

		filter_cursor.moveToFirst();

		while (!filter_cursor.isAfterLast()) {
			Map<String, Object> listItem = new HashMap<String, Object>();

			temp_type = filter_cursor.getString(filter_cursor
					.getColumnIndex(CallLog.Calls.TYPE));
			if (temp_type.equals(IncomingCall)) {

				temp_name = filter_cursor.getString(filter_cursor
						.getColumnIndex(CallLog.Calls.CACHED_NAME));
				temp_number = filter_cursor.getString(filter_cursor
						.getColumnIndex(CallLog.Calls.NUMBER));
				temp_date = filter_cursor.getString(filter_cursor
						.getColumnIndex(CallLog.Calls.DATE));
				temp_duration = filter_cursor.getString(filter_cursor
						.getColumnIndex(CallLog.Calls.DURATION));

				// 下面使用的日期类，实现日期的转换，从long类型的时间转换为可读的具体日期。
				SimpleDateFormat sfd = new SimpleDateFormat(
						"yyyy-MM-dd hh:mm:ss");
				Date date_converted = new Date(Long.parseLong(temp_date));

				// date为转换后的日期字符串
				String date = sfd.format(date_converted);

				listItem.put("date", date);
				listItem.put("duration", temp_duration + "秒");

				if (temp_name == null) {

					temp_name = "未知";
				}

				listItem.put("name", temp_name);
				listItem.put("type", Incoming_text);
				listItem.put("number", temp_number);

				list_incoming.add(listItem);
				temp_name = null;
			}
			filter_cursor.moveToNext();

		}
		return list_incoming;
	}
	
	public static List<Map<String, Object>> Display_Outgoing(Cursor filter_cursor){
		return null;
	}
	
	public static List<Map<String, Object>> Display_Missed(Cursor filter_cursor){
		return null;
		
		
	}
}
